package com.nameless.controller;

import com.nameless.service.WiXinRechargeService;
import com.nameless.vo.Result;
import com.nameless.vo.pay.RequestParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 微信支付
 *
 * @author 太阳偷渡青山
 * @program: qy158-weixin
 * @description:
 * @date 2023/03/05
 */
@RestController
@RequestMapping("/payment/weixin")
public class WeiXinController {

    @Autowired
    private WiXinRechargeService orderService;

    /**
     * 创建微信 Native 自动生成单号 并返回二维码信息
     *
     * @param requestParams 请求参数
     * @return {@link Result}<{@link Map}<{@link String},{@link Object}>>
     */
    @PostMapping("createNative")
    public Result<Map<String,Object>> createNative(@RequestBody RequestParams requestParams ){
            return orderService.createNative(requestParams.getClientId(),requestParams.getDescribe(),
                    requestParams.getMoney(),requestParams.getReturnUrl());
    }

    /**
     * 支付现有的单号信息
     *
     * @param requestParams 请求参数
     * @return {@link Result}<{@link Map}<{@link String},{@link Object}>>
     */
    @PostMapping("payExistingOrder")
    public Result<Map<String,Object>> payExistingOrder(@RequestBody RequestParams requestParams ){
        return orderService.payExistingOrder(requestParams.getOrderNo(),requestParams.getDescribe(),
                requestParams.getMoney(),requestParams.getReturnUrl());
    }

    /**
     * 查询支付状态
     *
     * @param orderNo 订单没有
     * @return {@link Result}<>
     */
    @GetMapping("queryPayStatus/{orderNo}")
    public Result<String> queryPayStatus(@PathVariable String orderNo){
         return orderService.queryPayStatus(orderNo);
    }
}
